package main

import (
	"./io"
	"./alayse"
	"fmt"
	"bytes"
	"image"
	"io/ioutil"
	_ "image/png"
	"image/color"
	"image/png"
	"os"
	"time"
)

func main() {
	decodePng("/Users/rich1/Pictures/1.png")
}

func getCompressionData(){
	pngContent := io.ReadAll("/Users/rich1/Pictures/1.png");
	fmt.Println(pngContent)
	decode := new(alayse.PngDecode);
	decode.Alayse(pngContent);
}

func decodePng(pngPath string) []byte {
	data,_ := ioutil.ReadFile(pngPath)
	img, _, _ := image.Decode(bytes.NewBuffer(data))
	newRgba := image.NewRGBA(img.Bounds())
	var ri uint8 = 100;
	var gi uint8 = 0;
	var bi uint8 = 0;
	fmt.Println(time.Now().UnixNano())
	for i:=0; i<img.Bounds().Dx(); i++{
		for j:=0; j<img.Bounds().Dy(); j++{
			colorRgb := img.At(i, j);
			r,g,b,a := colorRgb.RGBA();
			r_uint8 := uint8(r >> 8)
			g_uint8 := uint8(g >> 8)
			b_uint8 := uint8(b >> 8)
			a_uint8 := uint8(a >> 8)
			r_uint8 = 255 - r_uint8
			g_uint8 = 255 - g_uint8
			b_uint8 = 255 - b_uint8
			if(ri == 255 && bi == 255 && gi == 255){
				ri = 0
				bi = 0
				gi = 0
			}else if(bi == 255 && gi == 255){
				ri++
				bi = 0;
				gi = 0;
			}else if(gi == 255){
				bi++
				gi = 0
			}else{
				gi++
			}
			newRgba.SetRGBA(i, j, color.RGBA{ri, bi, gi, a_uint8})
			//if(i >= 200 && i <= 600 && (j == 200 || j == 600)){
			//	newRgba.SetRGBA(i, j, color.RGBA{0, 0, 0, a_uint8})
			//}else if(j == i && j >= 200 && j <= 600 ){
			//	newRgba.SetRGBA(i, j, color.RGBA{0, 0, 0, a_uint8})
			//} else{
			//	newRgba.SetRGBA(i, j, color.RGBA{255, 255, 255, a_uint8})
			//}
		}
	}
	f,_ := os.Create("/Users/rich1/Pictures/3.png")
	png.Encode(f, newRgba)
	//fmt.Printf("img:%v str:%s, err:%v", img, str, err);
	//decode := new(alayse.PngDecode)
	//decode.Alayse(img.)
	fmt.Println(time.Now().UnixNano())
	return nil;
}

